package com.compass.mobile.presenters

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.leanback.widget.Presenter
import com.compass.mobile.R
import com.compass.mobile.models.HospitalBean
import dp2px
import setUrl
import setUrlRound

/**
 * Description： 医院presenter
 * Date:2024/5/21 16:52
 */
class HospitalPresenter : Presenter() {
    override fun onCreateViewHolder(viewGroup: ViewGroup): ViewHolder {
        val view =
            LayoutInflater.from(viewGroup.context).inflate(R.layout.item_hospital, viewGroup, false)
        return ViewHolder(view)
    }

    override fun onBindViewHolder(viewHolder: Presenter.ViewHolder, item: Any) {
        if (item is HospitalBean) {
            val vh = viewHolder as ViewHolder
            vh.tvTitle.text = item.name
            vh.tvValue.text = item.rankText
            vh.imgBack.setUrlRound(item.logo,dp2px(10f))
        }
    }

    override fun onUnbindViewHolder(viewHolder: Presenter.ViewHolder) {}
    class ViewHolder(view: View) : Presenter.ViewHolder(view) {
        var tvTitle: TextView
        var tvValue: TextView
        var imgBack: ImageView

        init {
            tvTitle = view.findViewById(R.id.tv_title)
            imgBack = view.findViewById(R.id.imgBack)
            tvValue = view.findViewById(R.id.tvValue)
        }
    }
}
